package net.kansun

import org.xml.sax.helpers.DefaultHandler
import org.xml.sax.Attributesimport java.io.FileInputStreamimport org.xml.sax.XMLReaderimport org.xml.sax.helpers.XMLReaderFactoryimport org.xml.sax.InputSource
/**
 * @author kan.sun
 *
 */
public class GXmlParser extends DefaultHandler
{
	private def localName;
	private def collecting;
	private def currentValue;
	
	private InputStream source;
	private XMLReader reader;
	
	GXmlParser(String filename)
	{
		source = new FileInputStream(filename);
		reader = XMLReaderFactory.createXMLReader();
		reader.setContentHandler(it);
		reader.setErrorHandler(it);
	}
	
	void startElement(String uri, String localName,String qName, Attributes attributes)
	{
		println "Detected new Element!"+qName;
		if (localName==null && !localName.equalsIgnoreCase(localName))
		{
			localName = localName;
			collecting = true;
		}
	}
	void endElement(String uri, String localName,String qName, Attributes attributes)
	{
		println "Left new Element!"+qName;
		
	}
	
	void execute()
	{
		reader.parse(new InputSource(source));
	}
	
	static void main(String[] args)
	{
		def parser = new GXmlParser("src/main/resources/test.xml");
		parser.execute();
	}
}